<?php

/**
 * This is the model class for table "reklame_jenis".
 *
 * The followings are the available columns in table 'reklame_jenis':
 * @property string $id_jenis_rek
 * @property string $jenis_rekening
 * @property string $id_rekening
 * @property string $no_rekening
 * @property string $kategori_reklame
 *
 * The followings are the available model relations:
 * @property ReklameTarifRokok[] $reklameTarifRokoks
 * @property ReklameTarif[] $reklameTarifs
 * @property Rekening $idRekening
 */
class ReklameJenis extends CActiveRecord
{
	public $nama_rekening;
        /**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'reklame_jenis';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('id_jenis_rek', 'required'),
			array('jenis_rekening', 'length', 'max'=>100),
			array('no_rekening', 'length', 'max'=>10),
			array('kategori_reklame', 'length', 'max'=>75),
			array('id_rekening', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id_jenis_rek, jenis_rekening, id_rekening, no_rekening, kategori_reklame', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'reklameTarifRokoks' => array(self::HAS_MANY, 'ReklameTarifRokok', 'id_jenis_rek'),
			'reklameTarifs' => array(self::HAS_MANY, 'ReklameTarif', 'id_jenis_rek'),
			'idRekening' => array(self::BELONGS_TO, 'Rekening', 'id_rekening'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id_jenis_rek' => 'Id Jenis Rek',
			'jenis_rekening' => 'Jenis Rekening',
			'id_rekening' => 'Id Rekening',
			'no_rekening' => 'No Rekening',
			'kategori_reklame' => 'Kategori Reklame',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;
                $criteria->alias="j";
                $criteria->select = 'j.*, r.nama_rekening';
                $criteria->join = 'inner join rekening r ON j.id_rekening = r.id_rekening';

		$criteria->compare('id_jenis_rek',$this->id_jenis_rek,true);
		$criteria->compare('jenis_rekening',$this->jenis_rekening,true);
		$criteria->compare('id_rekening',$this->id_rekening,true);
		$criteria->compare('no_rekening',$this->no_rekening,true);
		$criteria->compare('kategori_reklame',$this->kategori_reklame,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return ReklameJenis the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
